<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.cr.model.Customer"%>
<%@ page import="com.cr.model.MyOrder"%>
<%@ page import="com.cr.service.ClothService"%>
<%@ page import="com.cr.service.MyOrderService"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My Orders</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="style/style.css">
	<script type="text/javascript" src="easyui/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="script/main.js"></script>
  </head>
  
  <body>
   	<jsp:include page="header.jsp"></jsp:include>
    <div id="content">
    	<div id="orders">
    		<%
    			Customer customer=null;
    		 	if(session.getAttribute("customer")!=null)
    		 	{
    		 		customer=(Customer)session.getAttribute("customer");
    		 	}
    		 	if(customer==null)
    		 	{
    		 		out.print("<script>location.href='login.jsp';</script>");
    		 	}
    			MyOrderService service=new MyOrderService();
    			String condition=" CustomerId="+customer.getId();
    			int pageSize=15;
    			int currPage=1;
    			int total=0;
    			total=service.getCount("");
    			int totalPage=0;
    			int nextPage=0;
    			int lastPage=0;
    			
    			if(total%pageSize==0)
    			{
    				totalPage=total/pageSize;
    			}
    			else
    			{
    				totalPage=total/pageSize+1;
    			}
    			if(currPage==1)
    			{
    				lastPage=1;
    			}
    			else
    			{
    				lastPage=currPage-1;
    			}
    			
    			if(currPage==totalPage)
    			{
    				nextPage=totalPage;
    			}
    			else
    			{
    				nextPage=currPage+1;
    			}
    			if(request.getParameter("page")!=null)
    			{
    				currPage=Integer.parseInt(request.getParameter("page"));
    			}
    			List<MyOrder> list=service.getOrders(currPage,pageSize,condition);
    		 %>
    		 <div style="padding-top:50px;">
    		 	<div id="menu_table">
    		 		<ul>
    		 			<li><a href="myorder.jsp">My Orders</a></li>
    		 			<li><a href="diyorder.jsp">Diy Orders</a></li>
    		 			<li><a href="modifyPassword.jsp">Modify Password</a></li>
    		 		</ul>
    		 	</div>
    		 	<div id="order_table">
    		 			<div id="pager">
    		 				<span><a href="myorder.jsp?page=1">首页</a></span>
    		 				<span><a href="myorder.jsp?page=<%=lastPage %>">上一页</a></span>
    		 				<span><a href="myorder.jsp?page=<%=nextPage %>">下一页</a></span>
    		 				<span><a href="myorder.jsp?page=<%=totalPage %>">尾页</a></span>
    		 				<span>(<%=currPage %>/<%=totalPage %>)</span>
    		 			</div>
    		 			<table border='1' style='border-collapse: collapse;width:650px;font-size:10pt;' bordercolor='#CCCCCC'>
    		 				<tr class="t_head">
    		 					<td>No.</td>
    		 					<td>Code</td>
    		 					<td>Client Name</td>
    		 					<td>Rent Days</td>
    		 					<td>Total</td>
    		 					<td>Date</td>
    		 					<td>Operaction</td>
    		 				</tr>
    		 				<%
			    		 		for(int i=0;i<list.size();i++)
			    		 		{
			    		 			MyOrder order=list.get(i);
			    		 			out.print("<tr class='t_item'>");
			    		 			out.print("<td>"+(i+1)+"</td>");
			    		 			out.print("<td>"+order.getCode()+"</td>");
			    		 			out.print("<td>"+order.getRecvName()+"</td>");
			    		 			out.print("<td>"+order.getRentDays()+"</td>");
			    		 			out.print("<td>"+order.getTotal()+"</td>");
			    		 			out.print("<td>"+order.getOrderDate()+"</td>");
			    		 			out.print("<td><a href='detail.jsp?id="+order.getId()+"'>Detail</a>&nbsp;&nbsp;<a href='modifyMyOrder.jsp?id="+order.getId()+"'>Modify</a>&nbsp;&nbsp;<a href='javascript:delOrder("+order.getId()+")'>Del</a></td>");
			    		 			out.print("</tr>");
			    		 	 	}
			    		 	  %>
    		 			</table>
    		 	</div>
    		 </div>
    	</div>
    </div>
    <jsp:include page="footer.jsp"></jsp:include>
  </body>
</html>
